﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="{x:Type TabItem}">
        <Setter Property="Background" Value="{DynamicResource TabItemHeaderBackgroundThemeBrush}" />
        <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderForegroundThemeBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TabItemHeaderBorderThemeBrush}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid x:Name="templateRoot" SnapsToDevicePixels="True">
                        <Border x:Name="mainBorder" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Margin="0" />
                        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                          ContentSource="Header" Focusable="False"
                                          HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}"
                                          Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ItemsControl}}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!--IsMouseOver-->
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Left" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderPointerOverBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderPointerOverForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Bottom" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderPointerOverBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderPointerOverForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Right" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderPointerOverBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderPointerOverForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderPointerOverBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderPointerOverForegroundThemeBrush}" />
                        </MultiDataTrigger>

                        <!--Is Enabled-->
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Left" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderDisabledBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderDisabledForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Bottom" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderDisabledBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderDisabledForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Right" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderDisabledBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderDisabledForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderDisabledBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderDisabledForegroundThemeBrush}" />
                        </MultiDataTrigger>

                        <!--Is Selected-->
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Left" />
                            </MultiDataTrigger.Conditions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Left" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="1" />
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderSelectedBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderSelectedForegroundThemeBrush}" />
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Bottom" />
                            </MultiDataTrigger.Conditions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Bottom" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="1" />
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderSelectedBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderSelectedForegroundThemeBrush}" />
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Right" />
                            </MultiDataTrigger.Conditions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Right" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="1" />
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderSelectedBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderSelectedForegroundThemeBrush}" />
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
                            </MultiDataTrigger.Conditions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
                                <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TabControl}}}" Value="Top" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Panel.ZIndex" Value="1" />
                            <Setter Property="Background" Value="{DynamicResource TabItemHeaderSelectedBackgroundThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TabItemHeaderSelectedForegroundThemeBrush}" />
                        </MultiDataTrigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter  Property="BorderBrush" Value="{DynamicResource ControlValidationInvalidThemeBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>